const Joi = require('joi');
const validationMiddleware = require('../../middleware/validate');
const router = require('koa-router')();
const { dealNotEmpty } = require("../../utils/dberrordeal");
const UserController = require('../../controllers/system/userController');
const { verify } = require('../../utils/auth');
router.use(verify);
const rulesSchema = {
    '/adduser': Joi.object({ username: dealNotEmpty('用户名') }),
    '/putuser': Joi.object({ username: dealNotEmpty('用户名') }),
    '/deluser': Joi.object({ id: dealNotEmpty('用户ID') }),
    '/getuser': Joi.object({ id: dealNotEmpty('用户ID') })
};
router.post('/adduser', validationMiddleware(rulesSchema), UserController.addUser);
router.post('/putuser', validationMiddleware(rulesSchema), UserController.updateUser);
router.post('/resetuser', UserController.resetUser);
router.post('/getuser', validationMiddleware(rulesSchema), UserController.getUserById);
router.post('/deluser', validationMiddleware(rulesSchema), UserController.deleteUser);
router.post('/auth', UserController.auth);
router.post('/getuserinfo', UserController.getUserInfo);
router.post('/login', UserController.login);
router.post('/getorole', UserController.getRoleById);
router.post('/getrole', UserController.getUserRole);
router.post('/userlist', UserController.getUserList);
module.exports = router;